package com.xcesys.extras.tool.exporter;

import java.io.File;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2x.GenericExporter;
import org.hibernate.tool.hbm2x.pojo.POJOClass;

public class ExtrasDaoExpporter extends GenericExporter {
	protected boolean impl = false;

	public ExtrasDaoExpporter() {
		init();
	}

	public ExtrasDaoExpporter(boolean impl) {
		this.impl = impl;
		init();
	}

	public ExtrasDaoExpporter(Configuration cfg, File outputdir) {
		super(cfg, outputdir);
		init();
	}

	public String getName() {
		return "model2dao";
	}

	protected String getPackageNameForFile(POJOClass element) {
		if (getProperties().containsKey("packageName")) {
			return getProperties().getProperty("packageName") + ".dao"
					+ (impl ? ".impl" : "");
		}
		return element.getPackageName();
	}

	protected void init() {
		setTemplateName("dao/dao" + (impl ? "Impl" : "") + ".ftl");
		setFilePattern("{package-name}/"  + (impl ? "" : "I")
				+ "{class-name}Dao" + (impl ? "Impl" : "") + ".java");
	}

	@Override
	protected String resolveFilename(POJOClass element) {
		return super.resolveFilename(element);
	}

	public void setImpl(boolean impl) {
		this.impl = impl;
	}
}
